package phan.connection;

import java.io.*;
import javax.jms.Session;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;



import java.util.List;

import java.util.*;
import java.io.*;
import java.io.InputStream;
import java.sql.*;

/**
 * Servlet implementation class for Servlet: LoginServlet
 *
 */
public class ContactNousServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#HttpServlet()
     */

    public ContactNousServlet() {
        super();
    }

    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    int i;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            //String StockName= request.getAttribute("selectid").toString();
 System.out.println("vao day ko?");
            String _usermail = request.getParameter("useremail").toString();
            String _question = request.getParameter("question").toString();
            System.out.println(_usermail);
            System.out.println(_question);
            String _adminmail = "dungbt84@gmail.com";
            String subject = "question";
            String host = "192.168.0.14";
            boolean check = false;
            MySQLDBConnector sendMail = new MySQLDBConnector();

            check = sendMail.sendMail(host, _usermail, _adminmail, subject, _question);

            //send ( host, from, to, subject, message );


            if (check) {
                //request.setAttribute ("user",);
                RequestDispatcher disp;
                disp = request.getRequestDispatcher("/PHAN/ContactNousSuccess.jsp");
                disp.forward(request, response);
            } else {
                request.setAttribute("isValide", "no");
                RequestDispatcher disp;
                disp = request.getRequestDispatcher("/retry.jsp");
                disp.forward(request, response);
            }
        // send ( host, from, to, subject, message );
        } catch (Exception e) {
            System.out.print("loi la " + e.getMessage());
        }
    }
}